import React, { useEffect, useRef } from "react";

function useDounce(callback, dealy) {
  const timer = useRef(null);
  useEffect(() => {
    if (timer.current) {
      clearInterval(timer.current);
    }
  }, []);

  return () => {
    if (timer.current) {
      clearInterval(timer.current);
    }

    timer.current = setInterval((...arg) => {
      callback(...arg);
    }, dealy);
  };
}

export default useDounce;
